package com.itheima.web;

import com.alibaba.fastjson.JSON;
import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;
import com.itheima.service.BrandServiceimp.brandServiceimp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

//@WebServlet("/SelectAllServlet")
public class SelectAllServlet extends HttpServlet {
    private BrandService brandService = new brandServiceimp();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用findAll方法
        List<Brand> allBrands = brandService.findAll();
        //转化为json格式
        String json = JSON.toJSONString(allBrands);
        //设置编码
        response.setContentType("application/json;charset=utf-8");
        //输出
        response.getWriter().println(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
